package net.onceface.web.resources;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.onceface.application.FeatureApplication;
import net.onceface.infra.json.JsonUtil;
@Path("/index")
public class IndexDataResource {

	@Inject
	private FeatureApplication featureApplication;
	@Inject
	//private PersonApplication application;
	
	@GET
	@Path("/getIndexData")
	@Produces({ MediaType.APPLICATION_JSON })
	public String getIndexData(@Context HttpServletResponse response){
		Map<String, Object> result = new HashMap<String, Object>();
		if (response != null){
    		response.setHeader("Access-Control-Allow-Origin", "*");
    	}
		result.put("feature", featureApplication.getIndexFeature());
		result.put("hot", featureApplication.getHotFeature());
		result.put("hasErrors", false);
		return JsonUtil.objectToJson(result);
	}
	
	/*@GET
	@Path("/getIndexData")
	@Produces({ MediaType.APPLICATION_JSON })
	public String getIndexData(){
		Map<String, Object> map = new HashMap<String, Object>();
		List<MenuDTO> menuList = menuApplication.findAllMenu();
		List<FeatureDTO> featureList = featureApplication.getIndexFeature();
		map.put("menu", menuList);
		map.put("feature", featureList);
		return JsonUtil.objectToJsonDateSerializer(map, "yyyy-MM-dd HH:mm:ss");
	}*/
}
